package com.aaron.study.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author liurong
 * @date 2021/9/5 21:08
 * @version:
 */
public class HashMapDemo {

    public static void main(String[] args) {
        //创建一个HashMap
        HashMap<String, String> map = new HashMap<>();
        map.put("k1", "v1");


        //添加元素 工号：员工姓名
        map.put("xx001", "张某");
        //修改
        map.put("xx001", "张三");
        //获取 xx001对应的值
        map.get("xx001");
        //删除 xx001对应的键值对
        map.remove("xx001");

        map.put("xx002", "李四");
        map.put("xx003", "王五");

        System.out.println("遍历方式1：通过keySet遍历key和value");
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            System.out.println("工号：" + key + " 姓名：" + map.get(key));
        }

        System.out.println("遍历方式2：通过Entry遍历key和value");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            System.out.println("工号：" + entry.getKey() + " 姓名：" + entry.getValue());
        }

        System.out.println("遍历方式3:通过values对value进行遍历");
        Collection<String> values = map.values();
        for (String value : values) {
            System.out.println("姓名：" + value);
        }

        map.entrySet();


    }

}

